<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css" />
	</head>

	<body>
		<div class="layui-tab page-content-wrap">
			<ul class="layui-tab-title">
				<li class="layui-this">信息修改</li>
			</ul>
			<div class="layui-tab-content">
				<!--站点配置-->
				<div class="layui-tab-item layui-show">

					<form class="layui-form" style="width: 90%;padding-top: 20px;">
						<input hidden th:value="${session.USER.userId}" name="userId">
						<div class="layui-form-item">
							<label class="layui-form-label">登录账户：</label>
							<div class="layui-input-block">
								<input type="text" name="userName" autocomplete="off" class="layui-input" th:value="${session.USER.userName}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">修改密码：</label>
							<div class="layui-input-block">
								<input type="password" name="newPassword"  autocomplete="off" class="layui-input" >
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">确认密码：</label>
							<div class="layui-input-block">
								<input type="password" name="newPassword2"  autocomplete="off" class="layui-input" >
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">旧密码：</label>
							<div class="layui-input-block">
								<input type="password" name="oldPassword" onkeydown="this.value=this.value.replace(/\s+/g,'')" autocomplete="off" class="layui-input" >
							</div>
						</div>

						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn layui-btn-normal" lay-submit lay-filter="siteInfo">立即提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script src="/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script>
			//Demo
			layui.use(['form', 'element','jquery'], function() {
				var form = layui.form();
				var element = layui.element();
				var $ = layui.jquery;
				form.render();
				//监听信息提交
				form.on('submit(siteInfo)', function(data) {
					//layer.msg(JSON.stringify(data.field));
					var newPas = ""+data.field.newPassword;
					var newPas2 = ""+data.field.newPassword2;
					if(newPas.indexOf(" ") != -1 || newPas2.indexOf(" ") != -1){
						layer.msg("密码不能包含空格！");
						return false;
					}
					var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
					if(reg.test(newPas) || reg.test(newPas2)){
						layer.msg("密码不能包含中文字符！");
						return false;
					}

					if(newPas == newPas2){
						$.ajax({
							url:"/admin/ajax/editAdmin",
							type:"POST",
							data:data.field,
							success:function (res) {
								if(res == 1){
									layer.msg("修改成功！",{end:function () {
											window.location.href="/";
										}});
								}else if(res == -1){
									layer.msg("旧密码错误！");
								}else{
									layer.msg("未知错误！");
								}

							}
						});
					}else{
						layer.msg("两次密码输入不一致！");
					}
					return false;
				});
			});
		</script>
	</body>

</html>